package com.wyp168.juc.sync;

/**
 * @ClassName SaleTicket
 * @Description TODO
 * @Author wyp168
 * @Date 2022/9/4 09:41
 */

class Ticket {
    private Integer ticketCount = 100;

    public synchronized void saleTicket() {
        while (ticketCount > 0) { //目前有票
            System.out.println(Thread.currentThread().getName() + "卖出第 " + ticketCount-- + "张票，剩余" + ticketCount + "张票");
            try {
                this.wait(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class SaleTicket {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        new Thread(ticket::saleTicket, "AA").start();
        new Thread(ticket::saleTicket, "BB").start();
        new Thread(ticket::saleTicket, "CC").start();
    }
}
